from django.views import View
# 导入返回响应
from SaaSDevelTool.data_return_response import create_response
# 导入错误信息装饰器
from SaaSDevelTool.data_return_response import error_message_detection
# 导入分页
from SaaSDevelTool.data_mysql_data import db

"""功能包展示"""


class SaaSDataSumResourcePackageQuery(View):
    @error_message_detection
    def get(self, request):
        # 拼接sql语句进行查询
        query_sum_package_table_sql = """
                SELECT 
                   p.package_id as value,
                   p.package_name as label,
                   smt.model_name  
                FROM 
                    db_saas_center.sum_package_table p
                LEFT JOIN  
                    db_saas_center.sum_model_table smt 
                ON 
                    p.model_id = smt.model_id 
                LEFT JOIN  
                    db_saas_center.sum_package_table p2 
                ON 
                    p.front_package_id = p2.model_id 
            ;"""
        # 调用方法查询语句
        query_sum_package_table_data = db.findAll(query_sum_package_table_sql)
        # 返回响应
        return create_response(code=200, msg="", data=query_sum_package_table_data)
